Ext.namespace('Divo');
Ext.namespace('Divo.app');
Divo.app.FlowPathList = function() {
  /* ----------------------- private属性 ----------------------- */
  var gridEl = 'FlowPath-grid';
  var htmlEditor, toolbar;
  /* ----------------------- private方法 ----------------------- */
  // 创建列表
  function createHtmlEditor() {
    htmlEditor = new Ext.form.HtmlEditor({
          tabIndex : 1,
          name : "flowPath",
          width : 800,
          hight : 500
        });
  }

  // 创建layout
  function createLayout() {
    toolbar = new Ext.Toolbar({
          items : [{
                icon : "resources/img/g_rec_commit.png",
                text : "保存",
                id : "tlb_SAVE",
                handler : save
              }, "-", {
                icon : "resources/img/g_rec_del.png",
                text : "删除",
                id : "tlb_DELETE",
                handler : deleteThis
              }]
        });
    var viewport = new Ext.Viewport({
          layout : 'border',
          items : [{
                layout : 'border',
                region : 'center',
                border : false,
                items : [{
                      layout : 'fit',
                      region : 'north',
                      border : false,
                      items : [toolbar],
                      height : 25
                    }, {
                      layout : 'fit',
                      region : 'center',
                      border : false,
                      items : [htmlEditor]
                    }]
              }]
        });
    viewport.doLayout();
  }

  function save() {
    Ext.Ajax.request({
          params : {
            content : htmlEditor.getValue()
          },
          url : "t_business/save_flow_path",
          callback : function(o, s, r) {
            var respText = Ext.decode(r.responseText);
            if (respText.success) {
              Ext.Msg.alert('成功', "保存成功！");
            } else {
              if (respText.message.length > 0) {
                Ext.Msg.alert('错误', respText.message);
              }
            }
          }
        });
  }
  
  function deleteThis() {
    Ext.Ajax.request({
          url : "t_business/delete_flow_path",
          callback : function(o, s, r) {
            var respText = Ext.decode(r.responseText);
            if (respText.success) {
              Ext.Msg.alert('成功', "删除成功！");
              loadContent();
            } else {
              if (respText.message.length > 0) {
                Ext.Msg.alert('错误', respText.message);
              }
            }
          }
        });
  }

  function loadContent() {
    Ext.Ajax.request({
          url : "t_business/query_flow_path",
          callback : function(o, s, r) {
            var respText = Ext.decode(r.responseText);
            if (respText.success) {
              htmlEditor.setValue(respText.content);
            } else {
              if (respText.message.length > 0) {
                Ext.Msg.alert('错误', respText.message);
              }
            }
          }
        });
  }

  /* ----------------------- public方法 ----------------------- */
  return {
    /**
     * 初始化
     */
    init : function() {
      createHtmlEditor();
      createLayout();
      loadContent();
    }
  }
}();

Ext.onReady(Divo.app.FlowPathList.init, Divo.app.FlowPathList, true);